<?php
namespace app\admin\controller;

use app\common\controller\AdminBaseController;
use app\common\enum\IsHistory;
use app\common\ext\IDb;
use app\common\ext\IRequest;

class UserPolicy extends AdminBaseController{

    /**
     * @功能：用户保单信息
     * @开发者：cxl
     * @return string
     */
    public function user_policy_list(){
        //接收参数
        $user_id = IRequest::get('user_id');
        $company_name = IRequest::get('company_name');
        $insured_name = IRequest::get('insured_name');
        $pay_type = IRequest::get('pay_type');
        $policy_type = IRequest::get('policy_type');
        $policy_status = IRequest::get('policy_status');

        //设置查询条件
        $where['is_history'] = IsHistory::not;
        if(!empty($user_id)) $where['user_id'] = $user_id;
        if(!empty($company_name)) $where['company_name'] = array("like","%{$company_name}%");
        if(!empty($insured_name)) $where['insured_name'] = array("like","%{$insured_name}%");
        if(!empty($pay_type)) $where['pay_type'] = $pay_type;
        if(!empty($policy_type)) $where['policy_type'] = $policy_type;
        if(!empty($policy_status)) $where['policy_status'] = $policy_status;
        $user_policy_list = IDb::getInstance('asset_policy')->setDbWhere($where)->setDbOrder("user_policy_id desc")->pag();
        if ($user_policy_list === false){
            error('获取保单列表失败');
        }

        //页面赋值
        $this->assign("user_id",$user_id);
        $this->assign("company_name",$company_name);
        $this->assign("insured_name",$insured_name);
        $this->assign("pay_type",$pay_type);
        $this->assign("policy_type",$policy_type);
        $this->assign("policy_status",$policy_status);
        $this->assign("user_policy_list",$user_policy_list);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：用户保单信息历史
     * @开发者：cxl
     * @return string
     */
    public function user_policy_info(){
        //接收参数
        $user_policy_id = IRequest::get('user_policy_id',IRequest::NOT_EMPTY,"用户保单编号不能为空！");

        //设置查询条件
        $user_policy_where['user_policy_id'] = $user_policy_id;
        $user_policy_info = IDb::getInstance('asset_policy')->setDbWhere($user_policy_where)->row();

        //设置layout
        $this->layout("layout_empty");

        //页面赋值
        $this->assign("user_policy_info",$user_policy_info);

        //渲染模板输出
        return view();
    }
}
